package 力扣题库;

public class p27移除元素 {
    public int removeElement(int[] nums, int val) {
        //双指针
        int left=0;
        int right=0;
        int len=nums.length;

        while (right<len) {
            if (nums[right] != val) {
                nums[left]=nums[right];
                left++;
            }
            right++;
        }
        return left;
    }

    public int removeElement1(int[] nums, int val) {
        int fast=0;
        int slow=0;

        int length=nums.length;//nums.length 得到的是数组长度这一属性

        while (fast < length) {
            if (nums[fast] == val) {
                fast++;
                continue;
            }else {
                nums[slow++] = nums[fast++];
            }
        }
        return slow;
    }


}
